﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Churchtoolkit.Utils.EmailProvider;
using Churchtoolkit.Web.Shell.Views;
using Churchtoolkit.Utils.MVP;
using Churchtoolkit.DataAccess.Repositories;
using Churchtoolkit.DataAccess.Entities;
using Churchtoolkit.DataAccess.Common;
using System.Net.Mail;
using Churchtoolkit.Utils.Authentication;


namespace Churchtoolkit.Web.Shell.Presenters
{
    public class ChurchInformationPresenter : Presenter<IChurchInformationView>
    {
        private IAuthentication _authentication;

        private MemberCommittiesRepository _memberCommitties;

        private MembersRepository _membersRepostiry;

        public ChurchInformationPresenter(IAuthentication authentication, MemberCommittiesRepository MemberCommitties , MembersRepository MemberRepository)
        {
            _membersRepostiry = MemberRepository;
            _memberCommitties = MemberCommitties;
            _authentication = authentication;
        }

        public void AddNewFather( string ConfessionFather)
        {
            var CurrentMember = _membersRepostiry.Find(m => m.Email = this._authentication.CurrentLogedInMember.Email).Single();

            CurrentMember.ConfessionFather = ConfessionFather;

            _membersRepostiry.Update(CurrentMember);
        }

        public void AddNewCommittie(string CommittieName, string Church)
        {
            MemberCommitties CurrentCommittie = new MemberCommitties();

            var CurrentMember = _authentication.GetCurrentMember();

            CurrentCommittie.MemberId = CurrentMember.MemberId;

            CurrentCommittie.Name = CommittieName;

            CurrentCommittie.Church = Church;

            _memberCommitties.Insert(CurrentCommittie);
        }

        public IEnumerable<MemberCommitties> CommittiesList()
        {
            var CurrentMember = _authentication.GetCurrentMember();

            EntityResult<MemberCommitties> committies = _memberCommitties.Find(items => { items.MemberId = CurrentMember.MemberId; });

            return committies;
        }
    }
}
